//
//  PHJBaseNavViewController.swift
//  新浪微博
//
//  Created by jie peng on 16/5/20.
//  Copyright © 2016年 jie peng. All rights reserved.
//

import UIKit

class PHJBaseNavViewController: UINavigationController , UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    
    //MARK:push的拦截方法
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        var backTitle = "返回"
        
        if childViewControllers.count>0 {
            if childViewControllers.count == 1 {
              backTitle = childViewControllers.first?.title ?? "返回"
            }
            let back = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: #selector(popVc))
            viewController.navigationItem.leftBarButtonItem = back
            
        }
        super.pushViewController(viewController, animated:animated)
    }
    @objc private func popVc(){
        self.popViewControllerAnimated(true)
    }
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        if childViewControllers.count>1 {
            return true
        }else{
            return false
        }
    }
}
